﻿using Hotel.Model;
using Hotle.BLL;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel_后端.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShopController : ControllerBase
    {
        public ShopController(ShopBLL bll)
        {
            Bll = bll;  
        }

        public ShopBLL Bll { get; }

        [HttpPost]
        //添加
        public IActionResult ShopAdd(ShopModel shop)
        {
            var aa = Bll.ShopAdd(shop);
            return Ok(aa);
        }

        /// <summary>
        /// 显示list
        /// </summary>
        /// <param name="toCount"></param>
        /// <param name="toPage"></param>
        /// <param name="name"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetShopList(string? name, int index = 1, int size = 3)
        {
            try
            {
                int toCount = 0;
                int toPage = 0;
                var list = Bll.GetShopList(out toCount, out toPage, name, index, size);
                return Ok(new
                {
                    list = list,
                    toCount = toCount,
                    toPage = toPage
                });
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="ids"多个ids字符串></param>
        /// <returns></returns>
        [HttpDelete]
        public IActionResult DelShopId(string ids)
        {
            var aa =  Bll.DelShopId(ids);
            return Ok(aa);
        }

        /// <summary>
        /// 批量修改状态
        /// </summary>
        /// <param name="ids"></param>
        /// <param name="steta"></param>
        /// <returns></returns>
        [HttpPut]
        public IActionResult Upsteta(string ids, int steta)
        {
            int res = Bll.Upsteta(ids, steta);
            return Ok(res);
        }


    }
}
